package com.atguigu.jxc.service.impl;

import com.atguigu.jxc.dao.DamageListDao;
import com.atguigu.jxc.dao.DamageListGoodsDao;
import com.atguigu.jxc.entity.DamageList;
import com.atguigu.jxc.entity.DamageListGoods;
import com.atguigu.jxc.entity.User;
import com.atguigu.jxc.service.DamageListGoodsService;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;

import javax.annotation.Resource;
import javax.xml.transform.Source;
import java.util.List;

/**
 * @author tongatong
 * @name damageListGoodsServiceImpl
 * @description
 * @date 2021/10/15
 * @time 19:37
 */
@Service
public class DamageListGoodsServiceImpl implements DamageListGoodsService {
    @Resource
    private DamageListGoodsDao damageListGoodsDao;
    @Resource
    private DamageListDao damageListDao;

    @Override
    public void save(DamageList damageList, List<DamageListGoods> damageListGoodsList, String damageNumber) {
        if (null != damageList && !CollectionUtils.isEmpty(damageListGoodsList)) {
            damageListDao.insert(damageList);
            /*System.out.println("============================================================");
            System.out.println(damageList.getDamageListId());*/
            damageListGoodsList.forEach(damageListGoods -> damageListGoods.setDamageListId(damageList.getDamageListId()));
            damageListGoodsDao.batchInsert(damageListGoodsList);
        }
    }

    @Override
    public List<DamageList> list(String sTime, String eTime, User user) {
        List<DamageList> damageListList = damageListDao.selectListByTime(user.getUserId(), sTime, eTime);
        damageListList.forEach(damageList -> {
            damageList.setTrueName(user.getTrueName());
            damageList.setUserId(user.getUserId());
        });

        return damageListList;
    }
}
